package FWK.components;

import java.awt.Cursor;

import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;

import FWK.exception.FwkUnsuportedTypeException;

public class FwkSortedTable<T> extends JTable implements FwkComponent{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8131308482851601064L;

	public FwkSortedTable(FwkAbstractResultadoModel<T> model) {
		this.setModel(model);
		JTableHeader header = this.getTableHeader();
		header.setUpdateTableInRealTime(true);
		header.addMouseListener(new HeaderListener<T>(this));
		header.setReorderingAllowed(true);
	}

	public void setModel(FwkAbstractResultadoModel<T> model) {
		super.setModel(model);
	}

	@SuppressWarnings("unchecked")
	public FwkAbstractResultadoModel<T> getModel() {
		return (FwkAbstractResultadoModel<T>) super.getModel();
	}

	public void setModel(TableModel dataModel) {
		if (dataModel.getClass().equals(FwkAbstractResultadoModel.class)) {
			throw new FwkUnsuportedTypeException("Solo se acepta modelos: " + FwkAbstractResultadoModel.class);
		}
	}

	@Override
	public void activate() {
		this.setEnabled(true);
		this.setCursor(Cursor.getDefaultCursor());
	}

	@Override
	public void standBy() {
		this.setEnabled(false);
		this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
		
	}
}
